<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
 
</head>

<body>

    <div>

    </div>



    <script>
        // 获取参数
        let odiv = document.querySelector('div');


        //创建ajax对象
        let ajax = new XMLHttpRequest();
        //配置请求信息
        ajax.open('get', '/index');
        // 发送请求
        ajax.send();

        // 等待响应
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
                //console.log(ajax.responseText);
                let data = JSON.parse(ajax.responseText);
                console.log(data);

                // 渲染
                let nr = '';
                data.forEach(value => {
                    nr += `<img src="${value.picture}" alt=""><p>${value.tradeName}</p><p>${value.price}</p><p>${value.stock}</p>`
                });
                odiv.innerHTML = nr;
            }
        }


    </script>

</body>

</html>